/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
(function($){
  $.upload = function (url ,form ,progress,callback){
      var data = new FormData(document.getElementById(form ));
      data.append("CustomField", "This is some extra data");
      var xhr = new XMLHttpRequest();

//      if(typeof progress == 'function'){
        xhr.addEventListener("progress", function(e){
            var position = e.position || e.loaded,
            total = e.totalSize || e.total;
            console.log(position)
            // progress(position , total );
        });
//      }

      xhr.open("POST",url, false)
      xhr.send(data);

      if (xhr.status == 200 && typeof callback == 'function') {
        callback()
      } else {
        console.log('error');
      }
  }
})(jQuery)

